﻿var shablon={};
var elements={};

shablon.init=function() 
{	
	elements.header=document.getElementById("header");
	elements.content=document.getElementById("content");
	elements.footer=document.getElementById("footer");
}


shablon.createHeader=function(logo_name) 
{
	elements.header.innerHTML="";
	// logo
	elements.logo=ui.logo(logo_name);
	elements.header.appendChild(elements.logo);
	// clock
	elements.clock=ui.clock();
	elements.header.appendChild(elements.clock);
		
	/*
	var banners_html = ''+
	'<div style="width: 786; height: 142; float: right;">'+
	'	<table cellpadding="0" cellspacing="0" width="100%" border="1">'+
	'		<tr id="tr_top5">'+
	'		</tr>'+
	'	</table>'+
	'</div>';
	
	*/
}

shablon.createIndexFooter=function(xml) 
{	
	elements.footer.innerHTML="";
	
	// логотипы банка, внизу страници
	// а текст поставляет сам ЕХЕ.
	var bank_text_contayner=document.createElement("span");
	//bank_text_contayner.style.width="100%";
	var bank_logos=xml.selectNodes("/req/index_logos/row");
	if  (bank_logos) {
		for (var i = 0; i < bank_logos.length; i++) {
			var bank_logo = bank_logos.item(i);
			var img_bank_logo=document.createElement('img');
			img_bank_logo.src=bank_logo.getAttribute("img");
			img_bank_logo.style.width="auto"
			img_bank_logo.style.height="auto"
			elements.footer.appendChild(img_bank_logo);
		}
	}
	
	// info
	var contayner_info=document.createElement('span');
	contayner_info.style.position="absolute";
	contayner_info.style.right="0";
	contayner_info.innerHTML="<img src='img/gosoplata/pages/index/info.jpg' onClick='location.href=\"info.html\";'/>"
	var node_info = xml.selectSingleNode("/req/index_buttons/row[@ord = 4]");
	if  (node_info) {
		contayner_info.innerHTML='<img src="' + node_info.getAttribute("img") + '" onclick="' + node_info.getAttribute("command").replace(/\*/g, "'").replace(/#/g, "\\") + '"/>';
	}
	elements.footer.appendChild(contayner_info);
	
	//elements.footer.appendChild(bank_text_contayner);
}

shablon.createNavigation=function(btn_next_type) 
{	
	if(!btn_next_type)btn_next_type='next';
	
	elements.footer.innerHTML="";
	elements.menu={};
	 
	var names=['back','menu','next'];
	var types=['back','menu'];
	types.push(btn_next_type);
	for(var i in names){
		var btn=ui.menu_button(types[i]);
		elements.menu["btn_"+names[i]]=btn;
		elements.footer.appendChild(btn);
	}
	
	elements.menu.btn_back.on_click=function(){
		history.back();	
	}
	elements.menu.btn_menu.on_click=function(){
		location.href = "index.html";	
	}
	elements.menu.btn_next.enabled(false);
}
	
shablon.user_data=function(node)
{
	var size=1130;
	
	var contayner=document.createElement("div");
	contayner.style.position="relative";
	//contayner.style.background="#ff0000"
	contayner.align="left";
	contayner.style.display="inline";
	contayner.style.width=size;
		
	// logo
	contayner.provider_logo=ui.operator_ico(node);	
	//contayner.provider_logo.style.background="#ff0000"	
	contayner.appendChild(contayner.provider_logo);
		
	// title
	contayner.$title = document.createElement("span");
	contayner.$title.style.position="relative";
	contayner.$title.style.left="20";
	//contayner.$title.style.background="#ff00ff";
	contayner.appendChild(contayner.$title);
	contayner.$title.style.verticalAlign="top";
	//contayner.$title.style.float="left";
	
	//form
	contayner.form = ui.form(node);
	contayner.appendChild(contayner.form);
	//contayner.form.style.background="#ff0000"	
	
	// content
	var next_page=node.getAttribute("next_page");
	if(!next_page && node.getAttribute("folder")=="cellular") next_page = "cellular.html";
	
	var pane,title,keyboard_type;
	var prefix="";
	var max_length = node.getAttribute("length");
	if (!max_length || max_length.length == 0) {
		max_length = 0;
	}
	var min_length=3;
	
	switch (next_page) {
		case "p_universal_kp.html":
			title="Введите номер <br/>договора/лицевого счета";
			keyboard_type='num';
			if(max_length==0)max_length=14;	
			
		break;
		case "p_universal_kb.html":
			title="Введите номер <br/>договора/лицевого счета";
			keyboard_type="full";
			if(max_length==0)max_length=30;
			
		break;
		case "cellular.html":
			title="<br/>Введите номер телефона";
			keyboard_type="num";
			max_length=10;
			min_length=10;
			prefix="8"
		break;
	}
	
	if(keyboard_type=='num')size-=340;
	
	pane=ui.prefix_input_fild(prefix,"",size);
	
	pane.max_length=max_length;
	pane.min_length=min_length;
	pane.regexp=node.getAttribute("regex");
	pane.input.input.name="getAccountNumber";
	contayner.form.add_fild(pane);
	
	contayner.form.clear();
	
	contayner.form.action="validate_confirm.html";
	contayner.form.on_submit=function(){
		document.cookie="Phone_Number=" +contayner.form.filds[0].get_dispay_value();
		contayner.form.submit();
	}
	
	contayner.$title.style.width=size-195;
	contayner.$title.innerHTML="<p class='form_title'>"+title+"</p>";
	
	contayner.form.style.width=size;
	
	// keypad
	var keypad=ui.keypad(keyboard_type);
	contayner.appendChild(keypad);
	keypad.style.top="20";
	if(keyboard_type=='num'){
		keypad.style.position="absolute";
		keypad.style.top="0";
		keypad.style.right="0";
	}else{
		//keypad.style.zoom=size/(92*14);
	}
	
	return contayner;
}